package com.tarry.shop.search.controller;

import com.tarry.shop.common.ResultEntity;
import com.tarry.shop.search.domain.dto.GoodsDTO;
import com.tarry.shop.search.service.GoodsSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("商品信息查询")
@RestController
@RequestMapping("es-goods")
@Validated
public class GoodsSearchController {

    @Autowired
    private GoodsSearchService goodsSearchService;

    @ApiOperation(value = "根据商品名称查询商品")
    @GetMapping("findByGoodsName")
    public ResultEntity<List<SearchHit<GoodsDTO>>> findByGoodsName(String goodsName){
        return ResultEntity.success(goodsSearchService.findAllByGoodsName(goodsName));
    }
}
